package com.f1ussh.serviceuser.controller;

import com.f1ussh.common.result.PageResult;
import com.f1ussh.common.result.Result;
import com.f1ussh.serviceuser.dto.PageDTO;
import com.f1ussh.serviceuser.dto.UserCreateDTO;
import com.f1ussh.serviceuser.dto.UserQueryDTO;
import com.f1ussh.serviceuser.dto.UserUpdateDTO;
import com.f1ussh.serviceuser.service.UserService;
import com.f1ussh.serviceuser.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author: 马腾飞
 * @CreateTime: 2025-10-01
 * @Description: 用户控制层
 * @Version: 1.0
 */

@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/list")
    public Result<PageResult<UserVO>> getUserPage(@Valid PageDTO pageDTO, UserQueryDTO queryDTO) {
        return userService.selectUserPage(pageDTO, queryDTO);
    }

    @GetMapping("/findById/{userId}")
    public Result<UserVO> getUserById(@PathVariable Long userId) {
        return userService.selectUserById(userId);
    }

    @PostMapping("/register")
    public Result<?> register(@Valid @RequestBody UserCreateDTO userCreateDTO) {
        return userService.register(userCreateDTO);
    }

    @PostMapping("/updateUser")
    public Result<?> updateUser(
            @RequestParam Long userId,
            @Valid @RequestBody UserUpdateDTO updateDTO) {

        return userService.updateUser(userId, updateDTO);

    }
}
